package cn.itcast.dubbo.controller;

import cn.itcast.dubbo.pojo.PageInfo;
import cn.itcast.dubbo.pojo.Provider;
import cn.itcast.dubbo.service.ProviderService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

/**
 * @author .
 * created in 2020/1/12 17:44
 */

@RestController
@RequestMapping(value = "/provider")
public class ProviderController {

    private Logger logger = LoggerFactory.getLogger(ProviderController.class);
    @Reference(version = "1.0.0")
    private ProviderService providerServiceImpl;


    @PostMapping(value = "/addProvider")
    public int addProvider(Provider provider) {
        return providerServiceImpl.addProvider(provider);
    }

    @PostMapping(value = "/delProvider/{id}")
    public int delProvider(@PathVariable("id") String id) {
        return providerServiceImpl.delProvider(id);
    }

    @PostMapping(value = "/updateProvider")
    public int updateProvider(Provider provider) {
        return providerServiceImpl.updateProvider(provider);
    }

    @GetMapping(value = "/findById/{id}")
    public Provider findById(@PathVariable("id") int id) {
        return providerServiceImpl.findById(id);
    }

    @GetMapping(value = "/findByName")
    public Provider findByName(@RequestParam("name") String name) {
        return providerServiceImpl.findByName(name);
    }

    @GetMapping(value = "/findAllByPage")
    public PageInfo<Provider> findAllByPage(PageInfo<Provider> info,
                                            @RequestParam(value = "name", defaultValue = "") String name) {
        return providerServiceImpl.findAll(info, name);
    }
}
